;(function(){
	'use strict';
	angular.module('services.analysisSysOM.cleanCount',[])
	.factory('cleanCountService',cleanCountService)
	.service('CtrlShowAndHide',CtrlShowAndHide);
	function cleanCountService(){
		return {
			getEchartsInstance: getEchartsInstance,
			getTimeTitle: getTimeTitle,
			exportView: exportView
		};
		function getEchartsInstance(result,title,xAxisName,seriesDataName,legendName,echartsType){
			var xAxisData = [];
			var seriesData = [];
			angular.forEach(result.data, function(res) {
				if (xAxisData.indexOf(res[xAxisName]) === -1) {
					xAxisData.push(res[xAxisName]);
					seriesData.push(res[seriesDataName]);
				}
			});
			var option = {
				title: {
					text: title,
					x: 'center'
				},
				animation: false,
				tooltip: {
		        trigger: 'axis'
		    },
				dataZoom: {
					show: true,
					realtime: true
				},
				grid: {
					x2: 130
				},
				legend: {
					data: [legendName],
					orient: 'vertical',
					x: 'right',
					y: 'center'
				},
				xAxis: [{
					type: 'category',
					data: xAxisData
				}],
				yAxis: [
	        {
	           type : 'value'
	        }
		    ],
				series: [
					{
						name: legendName,
						type: echartsType,
						data: seriesData
					}
				]
			};
			return option;
		}
		function getTimeTitle(params,timeType){
			var year = params.time.substring(0,4);
			var month = params.time.substring(5,7);
			var day = params.time.substring(8,10);
			if(timeType === 'first'){
				return year+'年'+month+'月'+day+'日';
			}
		}
		function exportView(send,flag,myEcharts){
			send.base64s = [];
			var b = myEcharts.getDataURL('png');
			send.base64s.push(b.split(',')[1]);
			flag.outData = JSON.stringify(send);
		}
	}
	function CtrlShowAndHide(){
		this.flag = {
			show:'view',
			state: true,
			arrow: false,
			items: [],
			title: '',
			outData:'',
		};
		this.destroyFn = function(){
			this.flag = {
				show:'view',
				state: true,
				arrow: false,
				items: [],
				title: '',
				outData:'',
			};
		};
	}
})();